"""
软件功能入口
"""

from constants.constant_config import MAIN_WINDOW, app


# 菜单栏功能入口

def menu_item_entry(menu_item_name, menu_list_name, secondary_menu=None):
    window1 = app.window(title=MAIN_WINDOW).child_window(title=menu_item_name, control_type="MenuItem")
    window1.click_input()
    window2 = app.window(control_type="Menu").child_window(title=menu_list_name, control_type="MenuItem")
    window2.click_input()
    if secondary_menu is not None:
        window3 = app.window(control_type="Menu", found_index=0).child_window(title=secondary_menu,
                                                                              control_type="MenuItem")
        window3.click_input()


# 工具栏功能入口
def toolbar_entry(button_name):
    app.window(title=MAIN_WINDOW).child_window(title=button_name, control_type="Button").click_input()


# 菜单窗口
def win_function(win_name, is_child_win=False):
    if is_child_win:
        window = app.window(title=MAIN_WINDOW).child_window(title=win_name, control_type="Window")  # 提示框是子框
        window.child_window(title="好的 Enter", control_type="Button").click_input()
    else:
        app.window(title=win_name, control_type="Window").click_input()


def close_window(win_name, is_Prompt_win=False):
    if is_Prompt_win:
        window = app.window(title=MAIN_WINDOW).child_window(title=win_name, control_type="Window")  # 提示框是子框
        window.child_window(title="关闭", control_type="Button").click_input()
    elif win_name == "新建项目":
        # 关闭按钮被屏蔽，只有取消按钮
        window = app.window(title="新建项目", control_type="Window")  # 目前功能入口与窗口不一致
        window.child_window(title="  取消", control_type="Button").click_input()
    elif win_name == "载入项目":
        window = app.window(title="项目选择框", control_type="Pane")
        window.child_window(title="取消", control_type="Button").click_input()
    elif win_name == "载入其他":
        window1 = app.window(title="发现项目", control_type="Window")
        window2 = window1.child_window(title="查找项目", control_type="Window")
        window2.child_window(title="关闭", control_type="Button").click_input()
        window1.child_window(title="关闭", control_type="Button").click_input()
    elif win_name == "全局校验":
        # 第一次提示选择硬先校验内容，第二次跳过弹出校验结果
        window1 = app.window(title="硬线选择校验", control_type="Window")
        hardline_check = window1.exists()
        if hardline_check:
            window1.child_window(title="确定 Enter", control_type="Button").click_input()
        else:
            window2 = app.window(title=MAIN_WINDOW).child_window(title="校验结果", control_type="Window")
            window2.child_window(title="关闭", control_type="Button").click_input()
    elif win_name == "刷新RFM":
        window1 = app.window(title=MAIN_WINDOW).child_window(title="提示", control_type="Window")
        window1.child_window(title="好的 Enter", control_type="Button").click_input()
        window2 = app.window(title="刷新RFM", control_type="Window")
        window2.child_window(title="关闭", control_type="Button").click_input()
    elif win_name == "基线比较" or win_name == "版本比较" or win_name == "权限管理":
        window1 = app.window(title=MAIN_WINDOW).child_window(title="提示", control_type="Window")
        window1.child_window(title="好的 Enter", control_type="Button").click_input()
    else:
        window1 = app.window(title=MAIN_WINDOW).child_window(title=win_name, control_type="Window").exists()
        window2 = app.window(title=win_name, control_type="Window").exists()
        if window1:
            window1 = app.window(title=MAIN_WINDOW).child_window(title=win_name, control_type="Window")
            window1.child_window(title="关闭", control_type="Button").click_input()
        if window2:
            window2 = app.window(title=win_name, control_type="Window")
            window2.child_window(title="关闭", control_type="Button").click_input()


if __name__ == '__main__':
    # toolbar_entry("全局搜索")
    # app.window(title="全局搜索", control_type="Window").click_input()
    # app.window(title="数据统计", control_type="Window").click_input()
    # win_function("全局搜索", False)
    # win_function("生成基线", True)
    # execute("全局搜索", "清除", "按钮")
    # close_window("生成基线", is_Prompt_win=True)



    pass
